package com.kaesar.thread_ressmix.atomic;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.LongAdder;

/**
 * @Author: chengk
 * @Date: 2021/8/31 6:16 下午
 */
public class LongAdderTest {
    public static void main(String[] args) throws InterruptedException {
        LongAdder longAdder = new LongAdder();
        List<Thread> list = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            Thread t = new Thread(new Runnable() {
                @Override
                public void run() {
                    longAdder.add(10);
                }
            });
            t.start();
            list.add(t);
        }

        for (Thread thread : list) {
            thread.join();
        }

        System.out.println(longAdder);
    }
}
